package cn.edu.swu.dlx;

import java.util.Random;
import java.util.Scanner;

public class Role {
    private String name;
    private int blood;
    private int attack;
    private String attackmethod;
    private int sillcount;
    public Role() {
    }

    public Role(String name, int blood, int sillcount) {
        this.name = name;
        this.blood = blood;
        this.sillcount = sillcount;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    public void setSillcount(int sillcount) {
        this.sillcount = sillcount;
    }

    public int getSillcount() {
        return sillcount;
    }

    public String getName() {
        return name;
    }

    public int getBlood() {
        return blood;
    }

    //定义攻击方法
    public void attack(Role attackedrole,Role attackrole) {
        Random random = new Random();
        int hurt = 0;
        int basicattack = random.nextInt(10)+1;
        int skill1 = random.nextInt(10)+10;
        int skill2 = random.nextInt(10)+20;
        int skill3 = random.nextInt(10)+30;
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入攻击方式：0.普通攻击 1.技能攻击 2.特殊攻击 3.大招");
        attack= sc.nextInt();
        if (attack>3) {
            System.out.println("攻击方式错误,请重新输入");
            attack= sc.nextInt();
        }
        if (this.sillcount<0) {
            System.out.println("技能点不足,请重新输入");
            attack= sc.nextInt();
        }

        switch (attack) {
            case 0:
                hurt = basicattack;
                this.attackmethod="普通攻击";
                attackrole.sillcount+=10;
                break;
            case 1:
                hurt = skill1;
                this.attackmethod="技能攻击";
                attackrole.sillcount-=20;
                break;
            case 2:
                hurt = skill2;
                this.attackmethod="特殊攻击";
                attackrole.sillcount-=30;
                break;
            case 3:
                hurt = skill3;
                this.attackmethod="大招";
                attackrole.sillcount-=40;
                break;
        }

        attackedrole.setBlood(attackedrole.getBlood() - hurt);
        System.out.println(this.name + "  使用了  "+this.attackmethod+"  攻击了  " + attackedrole.getName() + "  造成了 " + hurt + " 点伤害");
        if (attackedrole.getBlood() <= 0) {
            System.out.println(attackedrole.getName() + "  血量不足，死亡");
        }
        else System.out.println(attackedrole.getName() + "  剩余血量：" + attackedrole.getBlood());
    }
}
